 <template>
	<view class="homepage">
		<div class="swiper">
			<div class="container">
				<div class="swiperBox"><u-swiper :list="home.swiper" keyName="image" showTitle :autoplay="true" height="170" circular @click="checkJumpInfo"></u-swiper></div>
			</div>
		</div>
		
		<!-- <div class="navBox">
			<div class="container">
				<ul>
					<li v-for="(nav, index) in home.navs" :key="index" @click="checkJumpInfo(nav)"><image :src="nav.img" mode="widthFix"></image></li>
				</ul>
			</div>
		</div> -->
		
		
		<!-- <div class="adBox">
			<div class="container"  @click="changePath(home.ads[0].path)">
				<image class="ad" :src="home.ads[0].image" mode="widthFix"></image>
			</div>
		</div> -->
		<div class="container">
			<h2 class="textTlt">近期招聘公告</h2>
		</div>
		<div class="ggList" v-if="!home.hidegg">
			<div class="container">
				
				<div class="topping" v-if="showTopping">
					<div class="arrowBox">置顶</div>
					<div class="item"  @click="toGgxq(showTopping.id)">
						<h3>
							{{ showTopping.title }}
						</h3>
						<div class="tags">
							<ul>
								<li><u-tag :text="showTopping.xm" size="mini" type="warning"></u-tag></li>
								<li><u-tag :text="showTopping.xq" size="mini" type="error"></u-tag></li>
							</ul>
						</div>
					</div>
				</div>
				<div class="items">
					<div class="item" v-for="(item, index) in showPageList" :key="index"  @click="toGgxq(item.id)">
						<h3>
							{{ item.title }}
						</h3>
						<div class="tags">
							<ul>
								<li><u-tag :text="item.xm" type="error" size="mini"></u-tag></li>
								<li><u-tag :text="item.xq" type="success" size="mini"></u-tag></li>
							</ul>
						</div>
						<div class="bottom">
							<div class="origin">{{fbsjList[index].o}}</div>
							<div class="time">{{fbsjList[index].t}}</div>
						</div>
						
					</div>
				</div>
				<ul class="pagination" v-if="maxPage > 1">
					<li @click="selectPage(0)">首页</li>
					<li @click="prevPage">上一页</li>
					<li>
						<span>第{{ page }}页/共{{ maxPage }}页</span>
					</li>
					<li @click="nextPage">下一页</li>
					<li @click="selectPage(maxPage - 1)">尾页</li>
				</ul>
			</div>
		</div>

		<u-gap height="10" bgColor="#eee"></u-gap>
		<share></share>
		<div class="name">{{ name }}</div>
	</view>
</template>

<script>
import { mapActions } from 'vuex';
import share from '../common/share/index.vue';
const db = wx.cloud.database()
export default {
	data() {
		return {
			name: "",
			home: {

			},
			info: {},
			showEnd:false,
			name: "",
			page: 1,
			maxPage: '',
			ggList: [],
			
			showGg: [],
			filterCity: "全部地市",
			cityList: ['全部地市','黑龙江', '哈尔滨', '齐齐哈尔', '牡丹江', '佳木斯', '大庆', '绥化', '鸡西', '伊春', '双鸭山', '黑河', '鹤岗', '七台河', '大兴安岭'],
			filterXm: "全部项目",
			xmList: ["全部项目","公务员","事业单位","医疗卫生","国企","选调生","教师招聘","公益性岗位","金融银行","基层工作者","遴选","社区工作者"],
			showCity: false,
			showXm: false,
			sort: ['黑龙江', '哈尔滨', '齐齐哈尔', '牡丹江', '佳木斯', '大庆', '绥化', '鸡西', '伊春', '双鸭山', '黑河', '鹤岗', '七台河', '大兴安岭'],
			
			mrxxList: [],
			fbsjList: []
		}
	},
	onShareAppMessage(options) {
		let shareObj = {
		    title: "雪恒教育丨白雪面试",
		    path: '/pages/index/index?name=' + this.name,
		    imageUrl: ''   
		};
		return shareObj
	},
	onShareTimeline(res) {
		let that = this;
		return {
			title: '雪恒教育丨白雪面试',
			query: "name=" + that.name
		};
	},
	onShow() {},
	onPullDownRefresh() {
		console.log('refresh');
		setTimeout(function() {
			uni.stopPullDownRefresh();
		}, 1000);
	},
	onPageScroll(e) {
		let that = this;
	},
	onLoad(options) {
		if (!options) {} else {
			this.name = options.name
		}
	},
	computed: {
		searchtimes() {
			return this.$store.getters.searchtimes ? this.$store.getters.searchtimes : '';
		},
		userphone() {
			return this.$store.getters.userphone ? this.$store.getters.userphone : '';
		},
		useropenid() {
			return this.$store.getters.useropenid ? this.$store.getters.useropenid : '';
		},
		username() {
			return this.$store.getters.username ? this.$store.getters.username : '';
		},
		loginpage() {
			return this.$store.getters.loginpage ? this.$store.getters.loginpage : '';
		},
		showPageList(){
			let that = this
			let arr = that.ggList.filter((item,index) => index < 5 * that.page && index >= 5 * that.page - 5)
			arr.map((item,index) => {
				that.getTime(item.id,index)
			})
			
			return arr
		},
		showTopping(){
			let arr = this.ggList.filter((item,index) => item.topping == true)
			return arr[0]
		}
	},
	mounted() {
		this.name = this.name ? this.name : this.username;
		this.LogSetName(this.name);
		
		let nowDate = new Date()
		let year = nowDate.getFullYear()
		let month = nowDate.getMonth() + 1
		let day = nowDate.getDate()
		let time = year + '-' + month + '-' + day
		
	},
	watch: {

	},
	created() {
		let that = this;
		let date = new Date()
		let year = date.getFullYear()
		let month = date.getMonth() + 1
		let day = date.getDate()
		month = month < 10 ? "0" + month : month
		day = day < 10 ? "0" + day : day
		let d = year + "-" + month + "-" + day
		that.getHome()
		that.getDateList()
		
		
		let time = year + '-' + (date.getMonth() + 1) + '-' + date.getDate()

	},
	methods: {
		...mapActions(['LogSetSearchtimes','LogSetPhone','LogSetOpenid','LogSetName','LogSetPage']),
		getHome(){
			let that = this
			db.collection('a_show_info').doc("db9fa98264195e7d000e00100f80d637")
				.get({
					success: function(res) {
						that.home = res.data
					}
				});
		},
		checkJumpInfo(e) {
			let that = this;
			let obj = e
			if(!isNaN(e)){
				obj = that.home.swiper[e]
			}
			if (obj.appid) {
				that.changeXcx(obj.appid, obj.path);
			} else if (obj.link) {
				that.changeWeb(obj.link);
			} else if (obj.path) {
				that.changePath(obj.path);
			} else {
				return;
			}
		},
		changePath(path) {
			let that = this;
				uni.navigateTo({
					url: path
				});
		},
		changeXcx(appid, path) {
			wx.navigateToMiniProgram({
				appId: appid,
				path: path,
				success(res) {
					console.log(res);
				},
				fail(e) {
					console.log(e);
				}
			});
		},
		changeWeb(webInfo) {
			uni.navigateTo({
				url: '../webview/index?href=' + encodeURIComponent(webInfo)
			});
		},
		sortBy(attr, rev) {
			//第二个参数没有传递 默认升序排列
			if (rev == undefined) {
				rev = 1;
			} else {
				rev = rev ? 1 : -1;
			}
			return function(a, b) {
				a = parseInt(a[attr]);
				b = parseInt(b[attr]);
				if (a < b) {
					return rev * -1;
				}
				if (a > b) {
					return rev * 1;
				}
				return 0;
			};
		},
		prevPage() {
			if (this.page == 1) return;
			this.page--;
		},
		// 下一页
		nextPage() {
			if (this.page == this.maxPage) return;
			this.page++;
		},
		selectPage(index) {
			this.page = index + 1
		},
		getDateList(){
			let that = this
			
			let obj = {}
			that.filterXm != "全部项目" ? obj.xm = that.filterXm : ""
			that.filterCity != "全部地市" ? obj.city = that.filterCity : ""
			
			uni.request({
				url: 'https://www.baixuemianshi.com/zpgg/gglist_2023.js',
				method: 'get',
				dataType: 'text',
				data: {
					sstimes: new Date()
				},
				success: function(res) {
					var resjson = JSON.parse(res.data);
					that.ggList = resjson
					that.maxPage = Math.floor(that.ggList.length / 5)
				}
			})
		},
		getTime(id,index){
			let that = this
			uni.request({
				url: 'https://www.baixuemianshi.com/zpgg/gglist/' + id + '.js',
				method: 'get',
				dataType: 'text',
				data: {
					sstimes: new Date()
				},
				success(res) {
					var resjson = JSON.parse(res.data);
					let t = resjson.fbsj
					let origin = resjson.origin
					let o = {
						t: t,
						o: origin
					}
					that.$set(that.fbsjList,index,o)
				}
			})
			
		},
		fn_filterCity(){
			let that = this
			that.page = 0
		},
		fn_filterXm(){
			let that = this
			that.page = 0
			that.getDateList()
		},
		confirmCity(e){
			wx.showLoading()
			this.filterCity = e.value[0]
			
			this.closePicker()
		},
		confirmXm(e){
			wx.showLoading()
			this.filterXm = e.value[0]
			
			this.closePicker()
			this.fn_filterXm()
		},
		closePicker(){
			this.showCity = false
			this.showXm = false
		},
		calHour(num){
			return Math.floor(num/1000/3600)
		},
		toGgxq(id){
			let that = this
			uni.navigateTo({
				url: '../ggxq/index?ggid=' + id
			})
		},
		richStyle(content){
			let that = this
			let newCon = content.replace(/<p>/gi,'<p style="font-size: 14px; line-height: 1.8; margin: 5px 0; text-indent: 1em">')
			return newCon
		},
	},
	components: {share}
};
</script>

<style>
@import url('./index.css');
</style>
